/*
 * Copyright 2016-2019 yoara
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package yhao.infra.service.datasource.stat;

/**
 * druid sql统计数据结构类
 *
 * @author yoara
 */
public class SqlStatInfo {
	private String sql;
	private String tableName;
	private long executeCount;
	private long totalTime;
	
	private long maxTimespan;
	private String maxTimespanOccurTime;
	private Object lastSlowParameters;
	
	private long concurrentMax;
	
	private long fetchRowCount;
	private long fetchRowCountMax;

	private long effectedRowCount;
	private long effectedRowCountMax;

	private long histogram0;
	private long histogram1;
	private long histogram2;
	private long histogram3;
	private long histogram4;
	private long histogram5;
	private long histogram6;
	private long histogram7;
	
	private long errorCount;
	private Throwable lastError;
	
	
	
	
	public String getSql() {
		return sql;
	}
	public void setSql(String sql) {
		this.sql = sql;
	}
	public String getTableName() {
		return tableName;
	}
	public void setTableName(String tableName) {
		this.tableName = tableName;
	}
	public long getExecuteCount() {
		return executeCount;
	}
	public void setExecuteCount(long executeCount) {
		this.executeCount = executeCount;
	}
	public long getTotalTime() {
		return totalTime;
	}
	public void setTotalTime(long totalTime) {
		this.totalTime = totalTime;
	}
	public long getMaxTimespan() {
		return maxTimespan;
	}
	public void setMaxTimespan(long maxTimespan) {
		this.maxTimespan = maxTimespan;
	}
	public String getMaxTimespanOccurTime() {
		return maxTimespanOccurTime;
	}
	public void setMaxTimespanOccurTime(String maxTimespanOccurTime) {
		this.maxTimespanOccurTime = maxTimespanOccurTime;
	}
	public Object getLastSlowParameters() {
		return lastSlowParameters;
	}
	public void setLastSlowParameters(Object lastSlowParameters) {
		this.lastSlowParameters = lastSlowParameters;
	}
	public long getConcurrentMax() {
		return concurrentMax;
	}
	public void setConcurrentMax(long concurrentMax) {
		this.concurrentMax = concurrentMax;
	}
	public long getFetchRowCount() {
		return fetchRowCount;
	}
	public void setFetchRowCount(long fetchRowCount) {
		this.fetchRowCount = fetchRowCount;
	}
	public long getFetchRowCountMax() {
		return fetchRowCountMax;
	}
	public void setFetchRowCountMax(long fetchRowCountMax) {
		this.fetchRowCountMax = fetchRowCountMax;
	}
	public long getEffectedRowCount() {
		return effectedRowCount;
	}
	public void setEffectedRowCount(long effectedRowCount) {
		this.effectedRowCount = effectedRowCount;
	}
	public long getEffectedRowCountMax() {
		return effectedRowCountMax;
	}
	public void setEffectedRowCountMax(long effectedRowCountMax) {
		this.effectedRowCountMax = effectedRowCountMax;
	}
	public long getHistogram0() {
		return histogram0;
	}
	public void setHistogram0(long histogram0) {
		this.histogram0 = histogram0;
	}
	public long getHistogram1() {
		return histogram1;
	}
	public void setHistogram1(long histogram1) {
		this.histogram1 = histogram1;
	}
	public long getHistogram2() {
		return histogram2;
	}
	public void setHistogram2(long histogram2) {
		this.histogram2 = histogram2;
	}
	public long getHistogram3() {
		return histogram3;
	}
	public void setHistogram3(long histogram3) {
		this.histogram3 = histogram3;
	}
	public long getHistogram4() {
		return histogram4;
	}
	public void setHistogram4(long histogram4) {
		this.histogram4 = histogram4;
	}
	public long getHistogram5() {
		return histogram5;
	}
	public void setHistogram5(long histogram5) {
		this.histogram5 = histogram5;
	}
	public long getHistogram6() {
		return histogram6;
	}
	public void setHistogram6(long histogram6) {
		this.histogram6 = histogram6;
	}
	public long getHistogram7() {
		return histogram7;
	}
	public void setHistogram7(long histogram7) {
		this.histogram7 = histogram7;
	}
	public long getErrorCount() {
		return errorCount;
	}
	public void setErrorCount(long errorCount) {
		this.errorCount = errorCount;
	}
	public Throwable getLastError() {
		return lastError;
	}
	public void setLastError(Throwable lastError) {
		this.lastError = lastError;
	}
	
	public SqlStatInfo concat(SqlStatInfo data)
	{
		assert this.sql != null;
		if(data == null)
			return this;
		if(!this.sql.equalsIgnoreCase(data.sql))
		{
			return this;
		}
		this.executeCount += data.executeCount;
		this.concurrentMax = Math.max(this.concurrentMax, data.concurrentMax);
		this.effectedRowCount += data.effectedRowCount;
		this.effectedRowCountMax = Math.max(this.effectedRowCountMax, data.effectedRowCountMax);
		this.errorCount += data.errorCount;
		this.executeCount += data.executeCount;
		this.fetchRowCount += data.fetchRowCount;
		this.fetchRowCountMax = Math.max(this.fetchRowCountMax, data.fetchRowCountMax);
		this.histogram0 += data.histogram0;
		this.histogram1 += data.histogram1;
		this.histogram2 += data.histogram2;
		this.histogram3 += data.histogram3;
		this.histogram4 += data.histogram4;
		this.histogram5 += data.histogram5;
		this.histogram6 += data.histogram6;
		this.histogram7 += data.histogram7;
		if(this.maxTimespan < data.maxTimespan )
		{
			this.lastSlowParameters = data.lastSlowParameters;
			this.maxTimespanOccurTime = data.maxTimespanOccurTime;
			this.maxTimespan = data.maxTimespan;
		}
		this.totalTime += data.totalTime;
		return this;
	}

}
